#!/usr/bin/perl

require "./quotamin-lib.pl";
&ReadParse();

my ($username, %user, $i, @u_quot, $dir, $mode,$euser_title, $display);
my ($sblock, $hblock, $status, @skmg, @hkmg, @selectoption);

$username = $in{"s_username"};
$dir = $in{"fsdir"};
$lable = $in{"vlable"};
$mode = $in{"checkedmode"};
$display = $in{"i_display"};

$euser_title = &text('editquota_title', $username, $lable);
&header($euser_title, "", "modifyquota", 0, 1);

&foreign_require("quota", "quota-lib.pl");

#@u_quot = ($ublock, sblock, hblock, ufiles, sfiles, hfiles)
@u_quot = &get_user_quota($username, $dir);

if(($u_quot[1] == 0) && ($u_quot[2] == 0))
{
	$status = $text{"status_limit_no"};
}
else
{
	$status = $text{"status_limit_ok"};
}

print "<form name=formedituser action=save_user.cgi method=post onsubmit='return onsubmit_form();'>";
print "<table class=mode1 border=0>";

@skmg = &blocks_to_KMG_str($u_quot[1]);


if($skmg[2] eq "float")
{
	$skmg[0] = sprintf("%.2f" ,$skmg[0]);
}
@hkmg = &blocks_to_KMG_str($u_quot[2]);

if($hkmg[2] eq "float")
{	
	$hkmg[0] = sprintf("%.2f" ,$hkmg[0]);
}

if($status eq $text{"status_limit_ok"})
{

	print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_nolimit();' value='nolimit'></td><td>$text{'editquota_lable_no_limit'}</td><td></td><td></td></tr>";
	print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_limit(\"$status\");' checked value='ok'></td><td>$text{'editquota_lable_hblock_limit'}</td><td><input name=h_input_num class=text type=text value=\"$hkmg[0]\"></td><td>";
}
else
{
	print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_nolimit();' checked value='nolimit'></td><td>$text{'editquota_lable_no_limit'}</td><td></td><td></td></tr>";
	print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_limit(\"$status\");' value='ok'></td><td>$text{'editquota_lable_hblock_limit'}</td><td><input name=h_input_num class=disabletext type=text disabled=true value='$status'></td><td>";
}

@selectoption = ("<option value='KB'>KB", "<option value='MB'>MB", "<option value='GB'>GB");

print "<select name=h_unit size=1>";
if($hkmg[1] eq "KB")
{
	$selectoption[0] = "<option selected value='KB'>KB";
}
if($hkmg[1] eq "MB")
{
	$selectoption[1] = "<option selected value='MB'>MB";
}
if($hkmg[1] eq "GB")
{
	$selectoption[2] = "<option selected value='GB'>GB";
}

print @selectoption;

print "</select>";
print "</td></tr>";
if($status eq $text{"status_limit_ok"})
{
	print "<tr><td></td><td>$text{'editquota_lable_sblock_limit'}</td><td><input name=s_input_num class=text type=text value=\"$skmg[0]\"></td><td>";
}
else
{
	print "<tr><td></td><td>$text{'editquota_lable_sblock_limit'}</td><td><input name=s_input_num class=disabletext type=text disabled=true value=\"$status\"></td><td>";
}
@selectoption = ("<option value='KB'>KB", "<option value='MB'>MB", "<option value='GB'>GB");
print "<select name=s_unit size=1>";

if($skmg[1] eq "KB")
{
	$selectoption[0] = "<option selected value='KB'>KB";
}
if($skmg[1] eq "MB")
{
	$selectoption[1] = "<option selected value='MB'>MB";
}
if($skmg[1] eq "GB")
{
	$selectoption[2] = "<option selected value='GB'>GB";
}

print @selectoption;

print "</select>";
print "</tr>";

print "</table>";

print "<table class=mode1 celladding=10 cellspacing=10>";
print "<tr><td>";
print "<input type=submit class=button1 name=edit_user_submit_ok onclick='return on_submit_ok_click();' value=\"$text{'edit_user_submit_ok'}\">";
print "</td><td>";
print "<input type=submit class=button1 name=edit_user_submit_cancle onclick='return on_submit_cancel_click();'value=\"$text{'edit_user_submit_cancel'}\">";
print "</td></tr>";
print "</table>";

#$username =~ s/\\/\\\\/;

print "<input name=s_username type=hidden value=\"$username\">";
print "<input name=fsdir type=hidden value=\"$dir\">";
print "<input name=vlable type=hidden value=\"$lable\">";
print "<input name=i_display type=hidden value=\"$display\">";

print "<input name=checkeddir type=hidden value=\"$dir\">";
print "<input name=checkedlable type=hidden value=\"$lable\">";
print "<input name=checkedmode type=hidden value=\"$mode\">";
print "<input name=sortmode type=hidden value='name'>";
print "</form>";

print <<EOF;
<script>

function onsubmit_form()
{
        document.forms[0].edit_user_submit_ok.disabled = true;
        document.forms[0].edit_user_submit_cancle.disabled = true;
}

function on_radio_click_nolimit()
{
	document.forms[0].h_input_num.disabled = true;
	document.forms[0].s_input_num.disabled = true;
	document.forms[0].h_input_num.style.backgroundColor = "#d4d0c8";
	document.forms[0].s_input_num.style.backgroundColor = "#d4d0c8";
}

function on_radio_click_limit(status)
{
	document.forms[0].h_input_num.disabled = false;
	document.forms[0].s_input_num.disabled = false;
	document.forms[0].h_input_num.style.backgroundColor = "#ffffff";
	document.forms[0].s_input_num.style.backgroundColor = "#ffffff";
	if(document.forms[0].h_input_num.value == status)
	{
		document.forms[0].h_input_num.value = 4;
	}
	if(document.forms[0].s_input_num.value == status)
	{
		document.forms[0].s_input_num.value = 4;
	}
}

function on_submit_ok_click()
{
	document.forms[0].action = "save_user_quota.cgi";
}

function on_submit_cancel_click()
{
	document.forms[0].action = "listuser.cgi";
}

</script>
EOF

&footer("/quotamin", $text{'index'});
